package com.mall.service.marketing.controller;

import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.SmsCoupon;
import com.mall.model.dto.SmsCouponDto;
import com.mall.service.marketing.service.SmsCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/coupon")
public class SmsCouponController {
    @Autowired
    private SmsCouponService smsCouponService;

    //添加优惠券
    @PostMapping("/create")
    public CommonResult create(@RequestBody SmsCouponDto smsCouponDto) {
        smsCouponService.create(smsCouponDto);
        return CommonResult.success(1, "添加成功");
    }

    //删除优惠券
    @PostMapping("/delete/{id}")
    public CommonResult deleteById(@PathVariable Long id) {
        smsCouponService.deleteOne(id);
        return CommonResult.success(1, "删除成功");
    }

    //根据优惠券名称和类型分页获取优惠券列表
    @GetMapping("/list")
    public CommonResult<CommonPage> getAll(String name, Integer pageNum, Integer pageSize, Integer type) {
        CommonPage page = smsCouponService.getAll(name, pageNum, pageSize, type);
        return CommonResult.success(page);
    }

    //修改优惠券
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable Long id ,@RequestBody SmsCouponDto smsCouponDto){
        smsCouponService.updateOne(id,smsCouponDto);
        return CommonResult.success(1, "修改成功");
    }

    //
    @GetMapping("/{id}")
    public CommonResult<SmsCouponDto> getOne(@PathVariable Long id){
        SmsCouponDto smsCouponDto=smsCouponService.findOne(id);
        return CommonResult.success(smsCouponDto);
    }

}
